#include "SysConfig.h"
#include <osgEarth/Config>
#include <osgEarth/StringUtils>
#include <osgDB/fstream>


SysConfig::SysConfig()
{
    this->server_ip = "";
    this->server_port = "";
    this->test = true;
    this->server = "http://127.0.0.1:15000/";
    this->output_url = "";
    stereo_scale = 1.0;

    osgEarth::Config doc;
    std::ifstream in("../user_data/hbt/config/sys.xml");

    if(!doc.fromXML(in)){
        return;
    }
    const osgEarth::Config* cfg = doc.child_ptr("config");
    if(!cfg) return;

    const osgEarth::Config* cit = 0;

    cit = cfg->child_ptr("server");
    if (cit){
        this->server = QString::fromStdString(cit->value());
    }
    cit = cfg->child_ptr("output_url");
    if (cit){
        this->output_url = QString::fromStdString(cit->value());
    }
    cit = cfg->child_ptr("citydb_path");
    if (cit){
        this->citydb_path = (cit->value());
    }

    cit = cfg->child_ptr("stereo_scale");
    if (cit){
        float fv = osgEarth::as(cit->value(),1.0);
        this->stereo_scale = fv;
    }
    cit = cfg->child_ptr("satellite");
    if (cit){
        this->satellite_path =(cit->value());
    }
    cit = cfg->child_ptr("terrain");
    if (cit){
        this->terrain_path = cit->value();
    }
    cit = cfg->child_ptr("roadmap");
    if (cit){
        this->roadmap_path = cit->value();
    }
}

SysConfig *SysConfig::intance()
{
    static SysConfig sc;
    return &sc;
}

